package com.sky.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMqConfiguration {
    @Bean
    public CustomExchange delayExchange(){
        Map<String,Object> args=new HashMap<>();
        args.put("x-delayed-type","direct");
        return new CustomExchange("delay_exchange", "x-delayed-message",true,false,args);
    }

    @Bean
    public Queue delayQueue() {
        // 属性参数 队列名称 是否持久化
        return new Queue("order_process_queue", true);
    }


    @Bean
    public Binding delayBinding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("delay_key").noargs();
    }

    @Bean
    public DirectExchange cacheDelExchange(){
        return new DirectExchange("cache_del_exchange");
    }

    @Bean
    public Queue cacheDelQueue(){
        return new Queue("cache_to_del_queue");
    }

    @Bean
    public Binding cacheDelBinding(){
        return BindingBuilder.bind(cacheDelQueue()).to(cacheDelExchange()).with("cacheDel");
    }


}
